import { genPinYinCode,genFirstPinYinCode } from "@/util/util";
import { validatenull } from '@/util/validate'
// 检查打印数量
export function checkPrintNumber(that) {
  var flag = true;
  for (let i = 0; i < that.dataList.length; i++) {
    if (isNaN(that.dataList[i].quantity) || that.dataList[i].quantity <= 0) {
      alert('请填写正确的打印数量')
      flag = false
      that.$refs['quantity' + i].focus()
      return flag
    }
  }
  return flag
}

// 检查品种价格
export function checkPrintPrices(that){
  var reg_price = /^([1-9]{1,1}\d{0,10})\.\d{2,2}--([1-9]{1,1}\d{0,10})\.\d{2,2}$/;
  var flag = true;
  for(let i = 0; i < that.dataList.length; i++){
    if(reg_price.exec(that.dataList[i].retailprice) == null){
      alert("零售价范围格式不正确!正确格式为: 12.00--45.00");
      that.$refs['retailprice' + i].focus()
      flag = false;
      return flag
    }else{
      var prices = that.dataList[i].retailprice.split("--");
      if(parseFloat(prices[0]) > parseFloat(prices[1])) {
          alert("价格顺序填写有误!请按从小到大的顺序填写!");
          that.$refs['retailprice' + i].focus()
          flag = false;
          return flag
      }
    }
  }
  return flag;
}

export function PrintAllocationBarcode(that) {
  let barCode = new Array();
  let quantity = new Array();
  let brandname = new Array();
  let spec = new Array();
  let color = new Array();
  let retailprice = new Array();
  let person = new Array();
  let guaranteeperiod = new Array();
  let batch = new Array();
  for (let i = 0; i < that.dataList.length; i++) {
    person[i] = that.userInfo.username
    let barcodeData=(validatenull(that.dataList[i].goodsBarcode)?that.dataList[i].barcode:that.dataList[i].goodsBarcode)
    barCode[i] = barcodeData
    quantity[i] = that.dataList[i].allocationQuantity
    spec[i] = that.dataList[i].spec
    color[i] = (that.dataList[i].color) ? that.dataList[i].color : ''
    retailprice[i] = that.dataList[i].price
    guaranteeperiod[i] = (that.dataList[i].invalidTime) ? that.dataList[i].invalidTime : ''
    batch[i] = (that.dataList[i].batch) ? that.dataList[i].batch : ''
    brandname[i] = that.dataList[i].brandName

  }
  var printtype = {
    "1": "3",
    "2": "2",
    "3": "5",
    "4": "4",
    "5": "4",
    "6": "3",
    "7": "4",
    "8": "3",
    "9": "4"
  };
  printBarCode(that, barCode, quantity, brandname, spec, color, retailprice, person, printtype, guaranteeperiod, batch);
}

// 条码打印
export function PrintBarcode(that) {
  let barCode = new Array();
  let quantity = new Array();
  let brandname = new Array();
  let spec = new Array();
  let color = new Array();
  let retailprice = new Array();
  let person = new Array();
  let guaranteeperiod = new Array();
  let batch = new Array();
  for (let i = 0; i < that.dataList.length; i++) {
    person[i] = that.userInfo.username
    let barcodeData=(validatenull(that.dataList[i].goodsBarcode)?that.dataList[i].barcode:that.dataList[i].goodsBarcode)
    barCode[i] = barcodeData
    quantity[i] = that.dataList[i].quantity
    spec[i] = that.dataList[i].spec
    color[i] = (that.dataList[i].color) ? that.dataList[i].color : ''
    retailprice[i] = that.dataList[i].goodsPrice || that.dataList[i].price
    guaranteeperiod[i] = (that.dataList[i].invalidTime) ? that.dataList[i].invalidTime : ''
    batch[i] = (that.dataList[i].batch) ? that.dataList[i].batch : ''
    brandname[i] = that.dataList[i].brandName || that.dataList[i].goodsName

  }
  var printtype = {
    "1": "3",
    "2": "2",
    "3": "5",
    "4": "4",
    "5": "4",
    "6": "3",
    "7": "4",
    "8": "3",
    "9": "4"
  };
  printBarCode(that, barCode, quantity, brandname, spec, color, retailprice, person, printtype, guaranteeperiod, batch);
}

// 条码打印
export function printBarCode(that, barCode, quantity, brandname, spec, color, retailprice, person, printtype,
  guaranteeperiod,
  batch) {
  var barCodes = new Array();
  var brandnames = new Array();
  var specs = new Array();
  var colors = new Array();
  var retailprices = new Array();
  var persons = new Array();
  var guaranteeperiods = new Array();
  var batchs = new Array();
  var dataLength=0;

  for (var i = 0; i < barCode.length; i++) {
    for (var a = 0; a < quantity[i]; a++) {
      barCodes[dataLength] = barCode[i];
      brandnames[dataLength] = brandname[i];
      specs[dataLength] = spec[i];
      colors[dataLength] = color[i];
      retailprices[dataLength] = retailprice[i];
      persons[dataLength] = person[i];
      if (guaranteeperiod) {
        guaranteeperiods[dataLength] = guaranteeperiod[i];
      } else {
        guaranteeperiods[dataLength] = '';
      }
      if (batch) {
        batchs[dataLength] = batch[i];
      } else {
        batchs[dataLength] = '';
      }
      dataLength++;
    }
  }

  let content = ''
  if (/^[1]/.test(barCodes[0])) {
    content = callPrint1(that, barCodes, brandnames, specs, colors, retailprices, persons)
  } else if (/^[2]/.test(barCodes[0])) {
    content = callPrint2(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[3]/.test(barCodes[0])) {
    content = callPrint3(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[4]/.test(barCodes[0])) {
    content = callPrint4(that, barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs);
  } else if (/^[5]/.test(barCodes[0])) {
    content = callPrint5(that, barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs);
  } else if (/^[6]/.test(barCodes[0])) {
    content = callPrint1(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[7]/.test(barCodes[0])) {
    content = callPrint7(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[8]/.test(barCodes[0])) {
    content = callPrint8(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[9]/.test(barCodes[0])) {
    content = callPrint9(that, barCodes, brandnames, specs, colors, retailprices, persons);
  }
}

export function callPrint1(that, barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print1(barCode, brandname, spec, color, retailprice, person,that);
}

export function Print1(barCode, brandname, spec, color, retailprice, person,that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }
  // for (var i = 0; i < printbarCode.length-1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4,1,30,0,"品牌:"+printbrandname[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.2,1,30,0,"类型:"+printspec[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1,30,0,"颜色:"+printcolor[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1,30,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}


export function callPrint2(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print2(barCode, brandname, spec, color, retailprice, person,that);
}

export function Print2(barCode, brandname, spec, color, retailprice, person,that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4,1,30,0,"品牌:"+printbrandname[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.2,1,30,0,"类型:"+printspec[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1,30,0,"颜色:"+printcolor[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1,30,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint3(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print3(barCode, brandname, spec, color, retailprice, person, that);
}

export function Print3(barCode, brandname, spec, color, retailprice, person, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4,1,30,0,"品牌:"+printbrandname[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.2,1,30,0,"类型:"+printspec[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1,30,0,"颜色:"+printcolor[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1,30,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint4(that,barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  var guaranteeperiod = '';
  var batch = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
    guaranteeperiod = guaranteeperiod + guaranteeperiods[cStr] + '|';
    batch = batch + batchs[cStr] + '|';
  }
  return Print4(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch, that);
}

export function Print4(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var printguaranteeperiod = new Array();
  printguaranteeperiod = guaranteeperiod.split('|');
  var printbatch = new Array();
  printbatch = batch.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"效期:"+printguaranteeperiod[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"批号:"+printbatch[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"效期:"+printguaranteeperiod[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,5.0,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint5(that,barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  var guaranteeperiod = '';
  var batch = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
    guaranteeperiod = guaranteeperiod + guaranteeperiods[cStr] + '|';
    batch = batch + batchs[cStr] + '|';
  }
  return Print5(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch, that);
}

export function Print5(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var printguaranteeperiod = new Array();
  printguaranteeperiod = guaranteeperiod.split('|');
  var printbatch = new Array();
  printbatch = batch.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"效期:"+printguaranteeperiod[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"批号:"+printbatch[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"效期:"+printguaranteeperiod[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,5.0,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint6(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print6(barCode, brandname, spec, color, retailprice, person, that);
}

export function Print6(barCode, brandname, spec, color, retailprice, person, that){
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length-1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(1);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2,0,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,2.2,0,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4,1,30,0,"品牌:"+printbrandname[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.2,1,30,0,"类型:"+printspec[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1,30,0,"颜色:"+printcolor[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1,30,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint7(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return this.Print7(barCode, brandname, spec, color, retailprice, person, that);
}

export function Print7(barCode, brandname, spec, color, retailprice, person, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"型号:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0.4,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(0);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.2,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.4,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"效期:"+printguaranteeperiod[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,5.0,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint8(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print8(barCode, brandname, spec, color, retailprice, person, that);
}

export function Print8(barCode, brandname, spec, color, retailprice, person, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0.4,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(0);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.2,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.4,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"效期:"+printguaranteeperiod[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,5.0,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function callPrint9(that,barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print9(barCode, brandname, spec, color, retailprice, person, that);
}

export function Print9(barCode, brandname, spec, color, retailprice, person, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode2.byDarkness,printConfig.printbarCode2.dXPos,printConfig.printbarCode2.dYPos,printConfig.printbarCode2.qSize,0,printbarCode[flag + 0].substring(13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandname[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"类型:"+printspec[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText3.byDarkness,printConfig.printText3.dXPos,printConfig.printText3.dYPos,printConfig.printText3.qSize,0,"颜色:"+printcolor[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText4.byDarkness,printConfig.printText4.dXPos,printConfig.printText4.dYPos,printConfig.printText4.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }

  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0.4,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(0);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.2,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.4,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"效期:"+printguaranteeperiod[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,5.0,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function PrintBand(that) {
  var barCode = new Array();
  var brandName = new Array();
  var quantity = new Array();
  var retailprice = new Array();
  for (var i = 0; i < that.dataList.length; i++) {
    barCode[barCode.length] = that.dataList[i].brandBarcode;
    brandName[brandName.length] = that.dataList[i].name;
    quantity[quantity.length] = that.dataList[i].quantity;
    retailprice[retailprice.length] = '';
  }
  printBarCodeForBrand(that,barCode, quantity, retailprice, brandName);
}

export function printBarCodeForBrand(that,barCode, quantity, retailprice, brandName) {
  var printCode = new Array();
  var retailprices = new Array();
  var brandNames = new Array();
  for (var i = 0; i < barCode.length; i++) {
    for (var a = 0; a < quantity[i]; a++) {
      printCode[printCode.length] = barCode[i];
      retailprices[retailprices.length] = retailprice[i];
      brandNames[brandNames.length] = brandName[i];
    }
  }
  let content = ''
  content = callPrintForBrand(printCode, retailprices, brandNames, that);

}

export function callPrintForBrand(printBarcode, retailprices, brandNames, that) {
  var str = '';
  var retailprice = '';
  var brandName = '';
  for (var cStr = 0; cStr < printBarcode.length; cStr++) {
    str = str + printBarcode[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    brandName = brandName + brandNames[cStr] + '|';
  }
  return Print10(str, retailprice, 0, brandName, that);
}

export function Print10(barCode, retailprice, flag, brandName, that) {
  var printConfig = JSON.parse(that.printConfig)
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printbrandName = new Array();
  printbrandName = brandName.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";

  // 采用递归，循环打印条码
  var flag = 0;
  var len = printbarCode.length - 1;
  printLoop();
  function printLoop(){
    if(flag < len){
      web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
      web_DSZPLPrintQrCodeExA(0,printConfig.qcode.byDarkness,printConfig.qcode.dXPos,printConfig.qcode.dYPos,printConfig.qcode.qSize,1,printbarCode[flag + 0]);
      web_DSZPLRotation(2);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printbarCode1.byDarkness,printConfig.printbarCode1.dXPos,printConfig.printbarCode1.dYPos,printConfig.printbarCode1.qSize,0,printbarCode[flag + 0].substring(0, 13));
      web_DSZPLRotation(3);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText1.byDarkness,printConfig.printText1.dXPos,printConfig.printText1.dYPos,printConfig.printText1.qSize,0,"品牌:"+printbrandName[flag + 0]);
      web_DSZPLPrintTextExA(0,"宋体",false,false,printConfig.printText2.byDarkness,printConfig.printText2.dXPos,printConfig.printText2.dYPos,printConfig.printText2.qSize,0,"价格:"+printretailprice[flag + 0]);
      //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
      web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
      function callBackFun(retVal){
        console.log("获取打印信息："+retVal.RtnVal[0]);
      }
      flag++
      setTimeout(printLoop,2000)
    }else{
      return false
    }
  }


  // for (var i = 0; i < printbarCode.length - 1; i++) {
  //   web_DSZPLPrintTextExA(2,"宋体",false,false,0,0,0,0,0,"");//打印开始
  //   web_DSZPLPrintQrCodeExA(0,30,1,0.4,0.8,1,printbarCode[i + 0]);
  //   web_DSZPLRotation(0);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.2,30,15,printbarCode[i + 0].substring(0, 13));
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,1,1.4,30,15,printbarCode[i + 0].substring(13));
  //   web_DSZPLRotation(3);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.4,1.5,22,0,"品牌:"+printbrandName[i + 0]);
  //   // web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"批号:"+printbatch[i + 0]);
  //   web_DSZPLPrintTextExA(0,"宋体",false,false,30,4.6,1.5,22,0,"价格:"+printretailprice[i + 0]);
  //   //web_DSZPLPrintQrCodeExA(0,byDarkness,dXPos,dYPos,QrSize,byErrLevel,data);
  //   web_DSZPLPrintTextExA(3,"宋体",false,false,0,0,0,0,0,"",callBackFun);//打印结束
  //   function callBackFun(retVal){
  //     console.log("获取打印信息："+retVal.RtnVal[0]);
  //   }
  // }
  return printstr
}

export function PrintJQ(text,num){
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < num; i++) {
    printstr = printstr + "^XA^LH10,10";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^BY2,2.0,10^LH0,0^AI26";
    printstr = printstr + "^FO100,110^AXN,10,10^FH\^FDRMB:^FS";
    printstr = printstr + "^FO150,110^AXN,10,10^FH\^FD"+text+"^FS";
    printstr = printstr + "^PQ1,0,1,Y^XZ";
  }
  return printstr
}

/* * * * * * * * * 商品标价签打印 * * * * * * * * */
export function printGoodsTag(that){
  let brandList = new Array()
  let supplyList = new Array()
  let unitTypeList = new Array()
  let priceList = new Array()
  let maxPriceList = new Array()

  for(let i = 0; i < that.dataList.length; i++){
    brandList[brandList.length] = that.dataList[i].id
    supplyList[supplyList.length] = that.dataList[i].supplyId
    unitTypeList[unitTypeList.length] = that.dataList[i].unitType
    priceList[priceList.length] = that.dataList[i].minPrice + '/' + that.dataList[i].maxPrice
  }

  let brandStr = brandList.join(',')
  let supplyStr = supplyList.join(',')
  let unitTypeStr = unitTypeList.join(',')
  let priceStr = priceList.join(',')

  let sqlstr = "";

  for(var i=0; i<that.dataList.length; i++){
    sqlstr = sqlstr +'select \'' +that.dataList[i].name  +'\'brandName,\''+that.dataList[i].supplyName
        +'\'bspsuppliername,\''+that.dataList[i].unitType  +'\'bdunitname,\''+that.dataList[i].minPrice +'/'+ that.dataList[i].maxPrice +'\' as price';
    if(i != that.dataList.length - 1){
      sqlstr = sqlstr + ' union all ';
    }
  }

  return sqlstr
}
